package net.oschina.app.adapter.tweetsadapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ldl on 2017/4/1.
 */

public class TweetsAdapter extends FragmentPagerAdapter {
    private List<Fragment> mFragmentList;    // fragment集合
    private List<String> mFragmentTitles; // tab文字集合

    public TweetsAdapter(FragmentManager fm, List<Fragment> mFragmentList, List<String> mFragmentTitles) {
        super(fm);
        this.mFragmentList = mFragmentList;
        this.mFragmentTitles = mFragmentTitles;
    }

    public void addFragment(Fragment fragment, String title) {
        mFragmentList.add(fragment);
        mFragmentTitles.add(title);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mFragmentTitles.get(position);
    }
}